import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import http from './request'
import 'element-ui/lib/theme-chalk/index.css';
Vue.config.productionTip = false
Vue.prototype.$http = http
Vue.use(ElementUI);
// 添加请求拦截器，在请求头中加token
http.interceptors.request.use(
  config => {
    if (window.localStorage.getItem('token')) {
      config.headers.token = window.localStorage.getItem('token');
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  });

//响应拦截器  对于响应过滤
http.interceptors.response.use(
  response => {
    if (response.data.code === 401) {
      window.location.href = '/login'
      this.$message.error("登录过期！");
    }
    return response;
  }
)
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})
